package com.home.mq;

import com.alibaba.fastjson.JSON;
import com.home.biz.MsgSendInfoBiz;
import com.home.entity.MsgSendInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionState;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.apache.rocketmq.spring.support.RocketMQUtil;
import org.springframework.messaging.Message;
import org.springframework.messaging.converter.StringMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@Service
@RocketMQMessageListener(topic = "test", consumerGroup = "string_consumer")
public class MqConsumer implements RocketMQListener<String> {

    @Resource
    MsgSendInfoBiz msgSendInfoBiz;
    @Override
    public void onMessage(String message) {

        //throw new RuntimeException("发送失败");
        log.info("------- StringConsumer received:{} \n", message);
        try {
            msgSendInfoBiz.insertInfo(message);
        }catch (Exception e){
            //记录异常信息
            e.printStackTrace();
        }

    }
}
